<template>
	<view class="content">
		<view class="topImg">
			<image class="topImg" src="/static/top.png"></image>
		</view>
		<!-- 切换语言 -->
		<!-- <view class="text-area" @click="changeLanguage">
			<text class="title">{{ app.language.selectLanguage }}</text>
			<image src="/static/qh.png"></image>
		</view> -->
		<!-- 搜索框 -->
		<view class="seach">
			<input type="text" :placeholder="app.language.gjz" v-model="seachTit" />
			<image src="/static/seach.png" @click="handleSeach"></image>
		</view>
		<!-- 轮播图 -->
		<swiper indicator-dots autoplay indicator-active-color="#2f8ef9" class="swiper">
			<swiper-item v-for="(item, index) in bannerList" :key="index">
				<image :src="item.url"></image>
			</swiper-item>
		</swiper>
		<!-- 连接页面 -->
		<view class="gg" @click="handlegg">
			<image class="topImg" src="/static/gg.png"></image>
			<view class="ggtext">
				<view class="bmfw">{{app.language.bmfw}}</view>
				<view class="wsb">{{app.language.wsb}}</view>
			</view>
		</view>
		<view class="gg1" @click="handlegg">
			<image class="topImg" src="/static/gg1.png"></image>
			<view class="ggtext">
				<view class="bmfw">{{app.language.userInfo}}</view>
				<view class="wsb">{{app.language.djxg}}</view>
			</view>
		</view>
		<!-- 安全防范宣传 -->
		<view class="news">
			<view class="newsH">
				<image class="xc" src="/static/xc.png"></image>
				<text class="newsName">{{ app.language.newsName }}</text>
				<text class="newsMore" @click="newsMore">{{ app.language.newsMore }}</text>
			</view>
			<view class="newsItem" v-for="(item, index) in newsList" @click="newsShow(item.uuid)"
				v-if="newsList.length>0">
				<image :src="imgUrl+item.coverImage" class="newsImg"></image>
				<view class="newsB">
					<view class="newsTit">{{item.title}}</view>
					<view class="newscon">{{app.language.ly}}：{{item.source}}</view>
					<view class="newsTime">{{app.language.fbTime}}：{{item.createTime}}</view>
				</view>
			</view>
		</view>
		<!-- 户籍咨询 -->
		<view class="kfBox" @click="handleKf">
			<image src="/static/aikf.png"></image>
			<!-- <view class="wyzx">{{ app.language.wyzxTitle }}</view> -->
		</view>
		<!-- 如果为数据为空显示暂无数据 -->
		<view v-if="newsList.length==0">
			<nullVue></nullVue>
		</view>
		<u-action-sheet @select="selectLanguageList" @close="closeLanguageList" :actions="languageList"
			:closeOnClickOverlay="true" :closeOnClickAction="true" :title="app.language.selectLanguage"
			:safeAreaInsetBottom="true" :show="showLanguageList">
		</u-action-sheet>

	</view>
</template>

<script>
	import {
		newsList
	} from '@/api/news.js'
	import nullVue from '@/components/null';
	const global = getApp().globalData;
	import config from '@/config'

	export default {
		components: {
			nullVue
		},
		data() {
			return {
				imgUrl: config.baseUrl,
				app: {
					global: global,
					name: global.appName,
					language: global.language
				},
				languageList: [{
						name: '简体中文'
					},
					{
						name: 'English'
					}
				],
				showLanguageList: false,
				bannerList: [],
				newsList: [],
				// 搜索关键词
				seachTit: ""
			}
		},
		onLoad() {
			this.getNews()
		},
		methods: {
			// 查询安全防范列表数据
			getNews() {
				uni.showLoading({
					title: this.app.language.jzz,
				});
				let data = {
					"": ""
				}
				newsList(data).then((res) => {
					if (res.code == 200) {
						uni.hideLoading();
						this.newsList = res.rows
						// 遍历banner数据
						for (let i = 0; i < res.total; i++) {
							let temp = {
								url: this.imgUrl + res.rows[i].coverImage,
							};
							this.bannerList.push(temp);
						}
					}
				})
			},

			// 点击搜索查询数据
			handleSeach() {
				let data = {
					"title": this.seachTit
				}
				newsList(data).then((res) => {
					if (res.code == 200) {
						this.newsList = res.rows
					}
				})
			},

			selectLanguageList(e) {
				switch (e.name) {
					case '简体中文':
						uni.setStorageSync('language', 'chinese')
						this.changeLanguage('chinese')
						break

					case 'English':
						uni.setStorageSync('language', 'english')
						this.changeLanguage('english')
						break
				}
			},
			changeLanguage(value) {
				this.showLanguageList = true
				getApp().setLanguage(value)
				uni.setLocale()
				// 直接从全局数据更新本地数据
				this.app.language = getApp().globalData.language
			},
			closeLanguageList() {
				this.showLanguageList = false
			},
			popTest() {
				uni.showModal({
					title: this.app.language.popTitleText,
					cancelText: this.app.language.popCancelText,
					confirmText: this.app.language.popConfirmText,
					content: this.app.language.popTestContentText
				})
			},

			// 点击更多跳转到新闻列表页
			newsMore() {
				uni.navigateTo({
					url: '/pages/news/list',
				});
			},

			// 点击更多跳转到新闻详情页
			newsShow(uuid) {
				uni.navigateTo({
					url: '../news/show?uuid=' + uuid,
				});
			},
			// 广告连接
			handlegg() {
				uni.switchTab({
					url: '../bmfw/index'
				});
			},
			// 客服
			handleKf() {
				uni.reLaunch({
					url: '/pages/kefu/list'
				});
				// uni.reLaunch({
				// 	url: '/pages/kefu/index'
				// });
			}
		}
	}
</script>

<style>
	.content {
		background-color: #fff;
	}

	.topImg {
		width: 100%;
	}

	.text-area {
		font-size: 24rpx;
		position: absolute;
		top: 20rpx;
		right: 20rpx;
		color: #fff;
	}

	.text-area image {
		width: 30rpx;
		height: 32rpx;
		position: relative;
		top: 7rpx;
		margin-left: 10rpx;
	}

	.seach {
		width: 90%;
		margin: 0 auto;
		display: flex;
		position: absolute;
		top: 110rpx;
		left: 0;
		right: 0;
	}

	.seach input {
		width: 88%;
		padding: 8rpx 25rpx;
		background-color: #fff;
		border-radius: 50rpx;
		font-size: 26rpx;
		color: #a7a7a7;
	}

	.seach image {
		width: 55rpx;
		height: 55rpx;
		margin-left: 10rpx;
		margin-top: 5rpx;
	}

	.swiper {
		height: 330rpx;
		background-color: #fff;
		width: 95%;
		margin: -124px auto 0;
		z-index: 9999;
		position: relative;
		box-shadow: 1px 1px 10rpx #ddd;
		border-radius: 10rpx;
	}

	.swiper image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.swiper swiper-item {
		border-radius: 10rpx;
		text-align: center;
	}

	.news {
		margin-top: 25rpx;
		padding: 0 20rpx;
	}

	.newsItem {
		display: flex;
		background-color: #fff;
		margin-top: 10rpx;
		border-radius: 5rpx;
		padding: 10rpx;
		border-bottom: 1px solid #ddd;
	}

	.newsImg {
		width: 220rpx;
		height: 150rpx;
		margin-right: 20rpx;
	}

	.newsB {
		position: relative;
		width: 65%;
	}

	.newsTit {
		font-size: 26rpx;
		font-weight: bold;
		margin: 10rpx 0;
		overflow: hidden;
		display: -webkit-box;
		/* 将对象作为弹性伸缩盒子模型显示 */
		-webkit-line-clamp: 1;
		/* 行数，值可以改，表示展示X行后多余的缩略展示 */
		-webkit-box-orient: vertical;
		/* 设置或检索伸缩盒对象的子元素的排列方式 */
		word-break: break-all;
		line-height: 40rpx;
	}

	.newscon {
		font-size: 24rpx;
		color: #aeaeae;
		margin: 10rpx;
		overflow: hidden;
		display: -webkit-box;
		/* 将对象作为弹性伸缩盒子模型显示 */
		-webkit-line-clamp: 2;
		/* 行数，值可以改，表示展示X行后多余的缩略展示 */
		-webkit-box-orient: vertical;
		/* 设置或检索伸缩盒对象的子元素的排列方式 */
		word-break: break-all;
		line-height: 40rpx;
		height: 76rpx;
	}

	.newsTime {
		font-size: 22rpx;
		color: #aeaeae;
		position: absolute;
		bottom: 10rpx;
	}

	.newsH {
		/* font-size: 28rpx;
		font-weight: bold; */
	}

	.newsH text {
		width: 46%;
		display: inline-block;
	}

	.newsName {
		font-size: 28rpx;
		font-weight: bold;
	}

	.newsMore {
		font-size: 24rpx;
		color: #b9b9b9;
		text-align: right;
	}

	.gg,.gg1 {
		width: 50%;
		height: 170rpx;
		width: 46%;
		margin: 20rpx auto;
		border-radius: 10rpx;
		position: relative;
		float: left;
		margin-left: 20rpx;
	}

	.gg image,.gg1 image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.ggtext,.ggtext {
		position: absolute;
		top: 33rpx;
		right: 32rpx;
	}

	.bmfw {
		font-size: 29rpx;
		color: #2270f3;
		margin-bottom: 18rpx;
		font-weight: bold;
		/* font-style: italic; */
		letter-spacing: 2rpx;
		/* 增加字符间距 */
	}
	
	.gg1 .bmfw{
		color: #f3b622!important;
	}
	
	.gg1 .wsb{
		background-color: #f3b622!important;
	}

	.wsb {
		font-size: 21rpx;
		color: #fff;
		background-color: #2270f3;
		/* border-radius: 50%; */
		padding: 10rpx;
		text-align: center;
		border-radius: 27rpx;
	}
	
	.xc{
		width: 45rpx;
		height: 40rpx;
		position: relative;
		top: 10rpx;
	}
	
	.kfBox {
		/* background-color: #2f8ef9; */
		color: #fff;
		font-size: 22rpx;
		text-align: center;
		/* width: 100rpx;
		height: 100rpx; */
		/* padding: 20rpx; */
		border-radius: 50%;
		/* box-shadow: 1px 1px 10rpx #ddd; */
		position: absolute;
		bottom: 244rpx;
		right: 0;
	}
	
	.kfBox image {
		width: 110rpx;
		height: 110rpx;
	}
</style>